package com.cz.second.kill.service.impl;

import com.cz.second.kill.service.ISecondKill;
import com.cz.second.kill.util.RedisUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>redis模拟秒杀</p>
 * <pre>
 * @author gitamacai
 * @date 2019/12/5 15:14
 * </pre>
 */
@Service("redisSecondKillImpl")
@Slf4j
public class RedisSecondKillImpl implements ISecondKill {
    @Autowired
    private RedisUtil redisUtil;

    @Override
    public Integer kill(String uid) {
        String secondkill = redisUtil.lpop("secondkill");
        if ("".equalsIgnoreCase(secondkill)) {
            return 0;
        } else {
            // 进行秒杀失败
            return Integer.parseInt(secondkill);
        }

    }
}
